package com.heima.behavior.service.mq.impl;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.mq.ApUserOperationsService;
import com.heima.common.constants.article.HotArticleConstants;
import com.heima.model.mess.app.NewBehaviorDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author XHui
 * @Since 2024/3/12 15:49
 * @Version 1.0
 */
@Slf4j
@Service
public class ApUserOperationsServiceImpl implements ApUserOperationsService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendUserOperationsToRabbitMQ(NewBehaviorDTO newBehaviorDTO) {
        rabbitTemplate.convertAndSend(
                HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE,
                JSON.toJSONString(newBehaviorDTO)
        );
        log.info("点赞行为，发送消息到队列 -> {}", JSON.toJSONString(newBehaviorDTO));
    }
}
